home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / prm.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  6KB  |  276 lines

  1. /* --------------------------------- prm.c ---------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Manage parameter files (*.prm).
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. void (FAR* FAR flight_models[])(OBJECT *p, int action) = {
  14.     dynamics_basic,
  15.     dynamics_classic,
  16.     dynamics_xplane,
  17.     dynamics_yplane,
  18.     dynamics_fplane
  19. };
  20.  
  21. static struct e_parms    *parms = 0;
  22. static struct e_parms    Tparm = {0};
  23.  
  24. #define READFLD        Tparm
  25.  
  26. #define READPID(name) \
  27.     READI (name.Kp),        \
  28.     READI (name.Iband),        \
  29.     READI (name.Ki),        \
  30.     READI (name.Dband),        \
  31.     READI (name.Kd),        \
  32.     READI (name.factor),        \
  33.     READI (name.range)
  34.  
  35. #define READGEAR(n) \
  36.     READI (gear[n].x),        \
  37.     READI (gear[n].y),        \
  38.     READI (gear[n].z),        \
  39.     READI (gear[n].dgmax),        \
  40.     READI (gear[n].dtp),        \
  41.     READI (gear[n].P),        \
  42.     READI (gear[n].Cv),        \
  43.     READI (gear[n].emax),        \
  44.     READI (gear[n].ur),        \
  45.     READI (gear[n].ub),        \
  46.     READI (gear[n].us),        \
  47.     READI (gear[n].rateup),        \
  48.     READI (gear[n].ratedn)
  49.  
  50. static struct FldTab FAR ParmTbl[] = {
  51.     READI (weight),
  52.     READI (Ixx),
  53.     READI (Iyy),
  54.     READI (Izz),
  55.     READI (Izx),
  56.  
  57.     READI (liftoff_speed),
  58.     READI (max_lift),
  59.     READI (min_lift),
  60.     READI (pitch_rate),
  61.     READI (roll_rate),
  62.     READI (eyez),
  63.     READI (eyey),
  64.     READI (gpitch),
  65.     READI (ceiling),
  66.     READI (stores[0]),
  67.     READI (stores[1]),
  68.     READI (stores[2]),
  69.     READI (stores[3]),
  70.     READI (stores[4]),
  71.  
  72.     READI (brake_mu),       /* friction: brakes applied */
  73.     READI (wheel_mu),       /* friction: freewheeling */
  74.  
  75.     READI  (mil_thrust),
  76.     READI (mil_sfc),
  77.     READI (ab_thrust),
  78.     READI (ab_sfc),
  79.     READI (fuel_capacity),
  80.     READI (Ea),            /* Engine rig ang vs. plane */
  81.     READI (Eb),            /* Engine off ang vs. plane */
  82.     READI (Er),            /* Engine off vs. cg */
  83.  
  84.     READI (wing_area),
  85.     READI (wing_span),
  86.     READI (wing_cord),
  87.     READI (ACy),        /* wing ac forward of cg */
  88.     READI (ACz),        /* wing ac upward of cg */
  89.     READI (Aoffset),        /* Wing rigging ang vs. plane */
  90.     READI (Cl0),        /* alpha where Cl=0 */
  91.     READI (maxCl),        /* max Cl for wing foil */
  92.     READI (minCl),        /* min Cl for wing foil */
  93.     READI (FEff),           /* deg eff alpha/degs flaps */
  94.     READI (FEffCl),        /* flaps Clmax rate/DegFlaps */
  95.     READI (lefEffCl),           /* Clmax/LE flaps deg */
  96.     READI (efficiency_factor),
  97.     READI (Cm0w),
  98.  
  99.     READI (tail_area),
  100.     READI (tail_span),
  101.     READI (TACy),        /* tail ac forward of cg */
  102.     READI (TACz),        /* tail ac upward of cg */
  103.     READI (Toffset),        /* Tail rigging ang vs. wing */
  104.     READI (Tvol),           /* tail volume */
  105.     READI (TmaxCl),
  106.     READI (TminCl),
  107.  
  108.     READI (rudd_area),
  109.     READI (rudd_span),
  110.     READI (RACy),        /* rudder ac forward of cg */
  111.     READI (RACz),        /* rudder ac upward of cg */
  112.     READI (RmaxCl),
  113.  
  114.     READI (Cdp0),        /* parasitic: profile */
  115.     READI (Cds),        /* parasitic: speed brakes */
  116.     READI (Cdg),        /* parasitic: gear */
  117.     READI (CdMK82),        /* parasitic: each MK82 */
  118.  
  119.     READI (MaxFlaps),        /* max flaps [ang] */
  120.     READI (MaxLEFlaps),        /* max LE flaps [ang] */
  121.     READI (MaxSpoilers),    /* max spoilers [ang] */
  122.     READI (MaxElevators),    /* max elevators [ang] */
  123.     READI (MaxAilerons),    /* max ailerons [ang] */
  124.     READI (MaxRudder),        /* max rudder [ang] */
  125.  
  126.     READI (AFamin),        /* min aoa to engage */
  127.     READI (AFrate),        /* flaps/aoa rate */
  128.     READI (AFmax),        /* max flaps authority */
  129.  
  130.     READI (ALEFamin),        /* leFlaps: min aoa to engage */
  131.     READI (ALEFrate),        /* leFlaps/aoa rate */
  132.  
  133.     READI (AErate),        /* speed rate */
  134.  
  135.     READI (APrate),        /* speed rate */
  136.  
  137.     READI (Cydr),        /* rudder sideforce */
  138.     READI (Cybeta),        /* vx damping */
  139.  
  140.     READI (Cm0),
  141.     READI (Cmde),        /* elevators effectiveness */
  142.     READI (Cmq),        /* pitch damping */
  143.     READI (Cmalpha),        /* stabilizer induced pitch */
  144.     READI (Cmalphadot),        /* alpha rate induced pitch */
  145.  
  146.     READI (Clda),        /* aileron effectiveness */
  147.     READI (Clp),        /* roll damping */
  148.     READI (Clbeta),        /* dihedral effect */
  149.     READI (Cldr),        /* roll from rudder */
  150.  
  151.     READI (Cndr),        /* rudder effectiveness */
  152.     READI (Cnr),        /* yaw damping */
  153.     READI (Cnbeta),        /* weathercock stability */
  154.     READI (Cnda),        /* ailerons induced yaw */
  155.     READI (Cnp),        /* roll induced yaw */
  156.  
  157.     READI (hudtype),
  158.  
  159.     READI (opt[0]),        /* options */
  160.     READI (opt[1]),        /* options */
  161.     READI (opt[2]),        /* options */
  162.     READI (opt[3]),        /* options */
  163.     READI (opt[4]),        /* options */
  164.     READI (opt[5]),        /* options */
  165.     READI (opt[6]),        /* options */
  166.     READI (opt[7]),        /* options */
  167.     READI (opt[8]),        /* options */
  168.     READI (opt[9]),        /* options */
  169.  
  170.     READPID (PIDthrottle),
  171.     READPID (PIDpitch),
  172.     READPID (PIDroll),
  173.  
  174.     READGEAR (0),
  175.     READGEAR (1),
  176.     READGEAR (2),
  177.     READGEAR (3),
  178.     READGEAR (4),
  179. {0, 0}};
  180.  
  181. #undef READFLD
  182. #undef READPID
  183. #undef READGEAR
  184.  
  185. extern struct e_parms * FAR
  186. parms_get (char *pname)
  187. {
  188.     struct e_parms    *parm;
  189.     int    i, l, t;
  190.     FILE    *pfile;
  191.     char    line[256];
  192.  
  193.     if (!pname)
  194.         return (parms);        /* use default */
  195.  
  196.     for (parm = parms; parm; parm = parm->next)
  197.         if (!stricmp (parm->name, pname))
  198.             return (parm);
  199.  
  200.     Sys->BuildFileName (st.filename, st.fdir, pname, PRM_EXT);
  201.     if (!(pfile = fopen (st.filename, RTMODE))) {
  202.         LogPrintf ("missing parms file: %s\n", st.filename);
  203.         return (0);
  204.     }
  205.  
  206.     st.lineno = 0;
  207.     for (i = 0; ParmTbl[i].type > 0; ++i) {
  208.         if (field_read (pfile, &ParmTbl[i], line) < 0)
  209.             goto badret;
  210.     }
  211.     fclose (pfile);
  212.  
  213.     if (!NEW (parm)) {
  214.         LogPrintf ("no memory for parms: %s\n", st.filename);
  215.         return (0);
  216.     }
  217.  
  218.     strncpy (Tparm.name, pname, sizeof (Tparm.name));
  219.     memcpy (parm, &Tparm, sizeof (Tparm));
  220.  
  221.     if (parms) {
  222.         parm->next = parms->next;    /* keep first as default */
  223.         parms->next = parm;
  224.     } else {
  225.         parm->next = 0;
  226.         parms = parm;
  227.     }
  228.  
  229.     if ((sizeof(flight_models)/sizeof(*flight_models)) < parm->opt[0])
  230.         parm->opt[0] = MODEL_BASIC;
  231.  
  232.     if (0 == parm->opt[1])
  233.         parm->opt[1] = 2;        /* response=stiff */
  234.  
  235.     if (0 == parm->opt[3]) {
  236.         if (MODEL_CLASSIC == parm->opt[0])
  237.             parm->opt[3] = 4;    /* turn rate=average */
  238.         else if (MODEL_BASIC == parm->opt[0])
  239.             parm->opt[3] = 8;    /* lift rate=standard */
  240.     }
  241.  
  242. /* Find a reasonable initial height for a parked plane. We place the gear
  243.  * at half depression and look for the tallest one.
  244. */
  245.     if (parm->opt[5] < 0) {
  246.         l = 0;
  247.         for (i = 0; i < rangeof(parm->gear) && parm->gear[i].z; ++i) {
  248.             t = -parm->gear[i].z - parm->gear[i].dgmax/2;
  249.             if (l < t)
  250.                 l = t;
  251.         }
  252.         parm->opt[5] = (short)(l/VONE);
  253.     }
  254.  
  255.     LogPrintf ("Plane    %s\n", st.filename);
  256.     LogPrintf ("         model %d\n", parm->opt[0]);
  257.  
  258.     return (parm);
  259.  
  260. badret:
  261.     fclose (pfile);
  262.     return (0);
  263. }
  264.  
  265. extern void FAR
  266. parms_free (void)
  267. {
  268.     struct e_parms    *p, *pp;
  269.  
  270.     for (p = parms; p; p = pp) {
  271.         pp = p->next;
  272.         DEL (p);
  273.     }
  274.     parms = 0;
  275. }
  276.